﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
using IService.DataDLL;
using IService.Model;
using IService.Data.IManager;

namespace IService.Data.OlbImpl.ManagerImpl
{
	public class TypeDaManagerImpl : ITypeDaManager
	{
		public DTVType GetTypeById(DTVType type)
		{
			try
			{
				type.Select();
				return type;
			}
			catch (Exception e)
			{
				return type;
			}
		}

		public DataTable GetSubTypeListByPid(Type infoType, int parentId, int bigTypeId)
		{
			try
			{
				string WhereClause = "[ParentId]=" + parentId + " and [BigTypeId]=" + bigTypeId;
				return DataAccess.Select(infoType, WhereClause, "[TypeName]");
			}
			catch (Exception e)
			{
				return null;
			}
		}

		//public DataTable GetParentTypeBySystem(Type infoType, string RegisterSystem, string Order)
		//{
		//    try
		//    {
		//        string bigtypeid = DTVBusiness.BigTypeManager.GetBigTypeIdBySystem(RegisterSystem);
		//        if (!string.IsNullOrEmpty(bigtypeid))
		//        {
		//            string WhereClause = "BigTypeId=" + bigtypeid + " and ParentId=0";
		//            return DataAccess.Select(infoType, WhereClause, Order);
		//        }
		//        else
		//        {
		//            return null;
		//        }
		//    }
		//    catch (Exception e)
		//    {
		//        return null;
		//    }
		//}

		//public DataTable GetTypesBySystem(Type infoType, string RegisterSystem, string Order)
		//{
		//    try
		//    {
		//        string bigtypeid = DTVBusiness.BigTypeManager.GetBigTypeIdBySystem(RegisterSystem);
		//        if (!string.IsNullOrEmpty(bigtypeid))
		//        {
		//            string WhereClause = "BigTypeId=" + bigtypeid + " and Id not in(select distinct ParentId from Yocos_Type)";
		//            return DataAccess.Select(infoType, WhereClause, Order);
		//        }
		//        else
		//        {
		//            return null;
		//        }
		//    }
		//    catch (Exception e)
		//    {
		//        return null;
		//    }
		//}

		public DataTable GetTypeListByYear(Type infoType, int year)
		{
			string WhereClause = string.Format(" Id in (select ProductTypeId from Yocos_Product where year([PublishTime])={0})", year);
			string Order = "[CreateTime] desc";
			return DataAccess.Select(infoType, WhereClause, Order);
		}

		public DataTable GetTypeListAll(Type infoType)
		{
			return DataAccess.SelectAll(infoType);
		}

		public DataTable GetTypeListPagin(Type infoType, PagingEntity pe)
		{
			return DataAccess.SelectPaging(infoType, pe);
		}

		public int CountSubType(Type infoType, string WhereClause)
		{
			return DataAccess.Count(infoType, WhereClause);
		}

		/// <summary>
		/// 更新
		/// </summary>
		/// <param name="type"></param>
		/// <returns></returns>
		public bool InsertType(DTVType type)
		{
			return DataAccess.Insert(type);
		}

		public bool UpdateType(DTVType type)
		{
			return DataAccess.Update(type);
		}

		public bool DeleteType(DTVType type)
		{
			return DataAccess.Delete(type);
		}

		public bool DeleteTypeByIds(Type infoType, string WhereClause)
		{
			return DataAccess.Delete(infoType, WhereClause);
		}
	}
}
